<!--# layout("/common/layout.html",{"jsBase":"/js/qaVideo/qaVideo/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="videoId" id="videoId">

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">标题</label>
				<div class="layui-input-inline" style="width: 500px">
                    <input type="text" name="title" id="title" autocomplete="off"  class="layui-input" >
				</div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-inline">
            <select name="type" id="type" selectValue="" promtion="请选择" lay-filter="typeselect">
                <option value="">请选择</option>
                <option value="1">视频</option>
                <option value="2">直播</option>
            </select>
        </div>
    </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <layui:image id="cover" tagName="封面图" tips=""/>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-inline">
                    <layui:simpleDataSelect name="customerId" value="" data="${customerInfoList}"
                                            attrId="customerId" attrName="customerName" layFilter="customerFilter" id="customer_author" laySearch="true" />
                    <input type="hidden" name="author" id="author" value=""/>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">标签</label>
                <div class="layui-input-block" style="width:512px" id="videoTags">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline" >
                <label class="layui-form-label">链接地址</label>
                <div class="layui-input-inline" style="width: 800px">
                    <input type="text" name="link" id="link" autocomplete="off"  class="layui-input" >
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">云视频ID</label>
                    <div class="layui-input-inline" style="width: 300px">
                        <input type="text" name="fileId" id="fileId" autocomplete="off" class="layui-input" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">时长</label>
                    <div class="layui-input-inline" style="width: 300px">
                        <input type="text" name="timeLength" id="timeLength" autocomplete="off" class="layui-input" placeholder="格式HH:mm:ss" >
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row" hidden id="live">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">上线时间</label>
                    <div class="layui-input-inline" style="width: 300px">
                        <input type="text" name="startTime" id="startTime" autocomplete="off" class="layui-input input-datetime" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">下线时间</label>
                    <div class="layui-input-inline" style="width: 300px">
                        <input type="text" name="endTime" id="endTime" autocomplete="off" class="layui-input input-datetime" >
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否收费</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="isFee" value="1" title="收费" checked>
                        <input type="radio" name="isFee" value="0" title="免费" >
                    </div>
                </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <input type="radio" name="videoStatus" value="1" title="启用" checked>
                    <input type="radio" name="videoStatus" value="0" title="禁用" >
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">简介</label>
                <div class="layui-input-block" style="width:800px;z-index: 888">
                    <div id="wxin-contentDesc" ></div>
                    <input type="hidden" name="introduce" id="introduce"/>
                </div>
            </div>
        </div>
    </div>
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script>

    let ueditor_config = {
        toolbars: [["undo", "redo", "|", "fontsize", "forecolor", "bold", "italic", "underline", "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight", "|", "directionalityltr", "directionalityrtl", "indent", "|", "simpleupload", "|",  "spechars", "source", "|", "searchreplace", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/upload/config",
        autoHeightEnabled: false,
        elementPathEnabled : false,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:500
    };
    var ue = UE.getEditor('wxin-contentDesc',ueditor_config);

    ue.ready(function() {

    });

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {
            return '${ctxPath}/upload/uploadImg.json';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }

    // 编辑
    setTimeout(function () {
        var bjcontentDesc=  document.getElementById("introduce").value;
        UE.getEditor('wxin-contentDesc').setContent(bjcontentDesc);
    },1000);


    Common.initImage();
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
    selectM: '../../../plugins/layui_extends/selectM',
}).define([ 'form', 'laydate', 'table','loading','qaVideoApi','selectM'], function(exports) {
    var form = layui.form;
    var qaVideoApi = layui.qaVideoApi;
    var index = layui.index;
    var isNew = true;
    var selectM = layui.selectM;
    var tagData = ${resTagList};
    <!--# if(!(isEmpty(qaVideoJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            var tagIns2 = selectM({
                //元素容器【必填】
                elem: '#videoTags'
                //候选数据【必填】
                ,data: tagData
                //默认值
                ,selected: [${selectedTags!}]
                //最多选中个数，默认5
                ,max : 1
                //input的name 不设置与选择器相同(去#.)
                ,name: 'videoTags'
                //值的分隔符
                ,delimiter: ','
                //候选项数据的键名
                ,field: {idName:'tagName',titleName:'tagName'}
            });
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                $("#introduce").val(ue.getContent());
                let type = $("#type option:selected").val();
                if(type==2){
                    var starttime = $('#startTime').val();
                    var endtime = $('#endTime').val();
                    if(starttime==null||endtime==null){
                        Common.info("上下线时间不能为空");
                        return ;
                    }
                    var start = new Date(starttime.replace("-", "/").replace("-", "/"));
                    var end = new Date(endtime.replace("-", "/").replace("-", "/"));
                    if(end<start){
                        Common.info("下线时间要比上线时间大");
                        return ;
                    }
                }
                form.on('submit(form)', function(){
                    qaVideoApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(qaVideoJson))){  -->
    var formJson = ${qaVideoJson};
    form.val("editform",formJson);
    show(formJson.type)
        // UE.getEditor('wxin-contentDesc').setContent(formJson.contentDesc);
    ue.execCommand('insertHtml', formJson.contentDesc);
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    <!--# } -->
    form.on('select(customerFilter)', function(data){
        $("#author").val($("#customer_author").find("option:selected").text());
    });

    form.on('select(typeselect)', function(data){
        show(data.value);
    });

    function show(value) {
        if(value==2){
            $("#live").show();
        }else{
            $("#live").hide();
            $("#startTime").val("");
            $("#endTime").val("");
        }
    }
});
</script>

